using SS;
using System;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.func
{
	public class frmConfigTempHum : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private TextBox txtT1;
		private Label label1;
		private TextBox txtT4;
		private Label label4;
		private TextBox txtT3;
		private Label label3;
		private TextBox txtT2;
		private Label label2;
		private Button btnCreate;
		private Button btnClose;
		private Func objFunc = new Func();
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.groupBox1 = new GroupBox();
			this.txtT4 = new TextBox();
			this.label4 = new Label();
			this.txtT3 = new TextBox();
			this.label3 = new Label();
			this.txtT2 = new TextBox();
			this.label2 = new Label();
			this.txtT1 = new TextBox();
			this.label1 = new Label();
			this.btnCreate = new Button();
			this.btnClose = new Button();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Controls.Add(this.txtT4);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.txtT3);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txtT2);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.txtT1);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new Point(5, 7);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(346, 136);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thời điểm giám sát";
			this.txtT4.Location = new Point(92, 104);
			this.txtT4.Name = "txtT4";
			this.txtT4.Size = new Size(245, 21);
			this.txtT4.TabIndex = 7;
			this.label4.AutoSize = true;
			this.label4.Location = new Point(7, 107);
			this.label4.Name = "label4";
			this.label4.Size = new Size(82, 15);
			this.label4.TabIndex = 6;
			this.label4.Text = "Thời điểm IV :";
			this.txtT3.Location = new Point(92, 77);
			this.txtT3.Name = "txtT3";
			this.txtT3.Size = new Size(245, 21);
			this.txtT3.TabIndex = 5;
			this.label3.AutoSize = true;
			this.label3.Location = new Point(8, 80);
			this.label3.Name = "label3";
			this.label3.Size = new Size(81, 15);
			this.label3.TabIndex = 4;
			this.label3.Text = "Thời điểm III :";
			this.txtT2.Location = new Point(92, 50);
			this.txtT2.Name = "txtT2";
			this.txtT2.Size = new Size(245, 21);
			this.txtT2.TabIndex = 3;
			this.label2.AutoSize = true;
			this.label2.Location = new Point(11, 53);
			this.label2.Name = "label2";
			this.label2.Size = new Size(78, 15);
			this.label2.TabIndex = 2;
			this.label2.Text = "Thời điểm II :";
			this.txtT1.Location = new Point(92, 23);
			this.txtT1.Name = "txtT1";
			this.txtT1.Size = new Size(245, 21);
			this.txtT1.TabIndex = 1;
			this.label1.AutoSize = true;
			this.label1.Location = new Point(14, 26);
			this.label1.Name = "label1";
			this.label1.Size = new Size(75, 15);
			this.label1.TabIndex = 0;
			this.label1.Text = "Thời điểm I :";
			this.btnCreate.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnCreate.FlatStyle = FlatStyle.Flat;
			this.btnCreate.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnCreate.Location = new Point(129, 149);
			this.btnCreate.Name = "btnCreate";
			this.btnCreate.Size = new Size(127, 26);
			this.btnCreate.TabIndex = 43;
			this.btnCreate.Text = "Lưu thông tin [ F6 ]";
			this.btnCreate.UseVisualStyleBackColor = true;
			this.btnCreate.Click += new EventHandler(this.btnCreate_Click);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(260, 149);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(91, 26);
			this.btnClose.TabIndex = 44;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(357, 181);
			base.Controls.Add(this.btnCreate);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.groupBox1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(373, 215);
			this.MinimumSize = new Size(373, 215);
			base.Name = "frmConfigTempHum";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "..: Cấu hình";
			base.Load += new EventHandler(this.frmConfigTempHum_Load);
			base.KeyDown += new KeyEventHandler(this.frmConfigTempHum_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
		}
		public frmConfigTempHum()
		{
			this.InitializeComponent();
		}
		private void frmConfigTempHum_Load(object sender, EventArgs e)
		{
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = "SELECT TOP 1 * FROM [TabConfigTempHum]";
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				this.txtT1.Text = sqlDataReader["T1"].ToString();
				this.txtT2.Text = sqlDataReader["T2"].ToString();
				this.txtT3.Text = sqlDataReader["T3"].ToString();
				this.txtT4.Text = sqlDataReader["T4"].ToString();
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmConfigTempHum_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				this.btnClose.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.F6)
				{
					this.btnCreate.PerformClick();
				}
			}
		}
		private void btnCreate_Click(object sender, EventArgs e)
		{
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = string.Concat(new string[]
			{
				"UPDATE [TabConfigTempHum] SET T1 = N'",
				this.txtT1.Text,
				"',T2 = N'",
				this.txtT2.Text,
				"',T3 = N'",
				this.txtT3.Text,
				"',T4 = N'",
				this.txtT4.Text,
				"'"
			});
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
			MessageBox.Show("Dữ liệu đã được cập nhật vào hệ thống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
		}
	}
}
